const TransformPages = require('uni-read-pages')
const {
	webpack
} = new TransformPages()
module.exports = {
	configureWebpack: {
		plugins: [
			new webpack.DefinePlugin({
				ROUTES: webpack.DefinePlugin.runtimeValue(() => {
					const tfPages = new TransformPages({
						includes: ['path', 'name', 'aliasPath', 'meta']
					});
					return JSON.stringify(tfPages.routes)
				}, true)
			})
		]
	},
	devServer: {
		proxy: {
			'/shyb': {
				target: 'http://192.168.3.152:8888',
				changeOrigin: true,
				secure: false,
				ws: true,
				pathRewrite: {
					'^/shyb': '/shyb'
				},
				onProxyReq: function(proxyReq, req, res) {
					// 添加跨域请求头
					proxyReq.setHeader('origin', 'http://192.168.3.152:8888');
					if (req.body) {
						const bodyData = JSON.stringify(req.body);
						proxyReq.setHeader('Content-Type', 'application/json');
						proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
					}
				}
			}
		},
		headers: {
			'Access-Control-Allow-Origin': '*',
			'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
			'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
		}
	}
}